// pages/learntime/index.js
var util = require('../../utils/util.js')
var api = require('../../config/api.js');
var app = getApp();



Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {
      ke1: "0",
      ke2: "0",
      ke3: "0",
      ke4: "0"
    },
    info2: {
      subject1: "",
      subject2: "",
      subject3: "",
      subject4: ""
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getXsDetail();
    this.queryhours();
  },
  getXsDetail: function () {

    let that = this;
    var userid = wx.getStorageSync("userid");
    if (userid == '') {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
      return;
    }
    console.log("学时查询！！！！用户信息=" + userid);
    util.request(api.queryMyLearnTime, {
      uid: userid,
      key:api.key
    }).then(function (res) {
      if (res.errno === 0) {
        console.log(JSON.stringify(res.data));
        var detail = res.data;
        that.setData({
          info: detail
        });
      }else if(res.errno === 402){
        wx.showModal({
          title: '错误',
          content:'不被允许的请求',
          showCancel: false
        })
    }
      wx.hideLoading();
    })
  },
  queryhours: function () {
    let that = this;
    var userid = wx.getStorageSync("userid");
    if (userid == '') {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
      return;
    }
    console.log("标准学时查询！！！！用户信息=" + userid);
    util.request(api.queryTime, {
      uid: userid
    }).then(function (res) {
      console.log(JSON.stringify(res.data));
      if (res.errno === 0) {
        //console.log(JSON.stringify(res.data));
        var detail = res.data;
        that.setData({
          info2: res.data
        });
        console.log(that.data.info2)
      }
      wx.hideLoading();
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  data: {
    contents: 'http://103.239.155.248:3700/'
  },
  copyText: function (e) {
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  }
})